package com.motorola.dp.jenkinsmonitor.service.process;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.motorola.dp.jenkinsmonitor.model.entity.JenkinsState;
import com.motorola.dp.jenkinsmonitor.model.util.HttpRequestParameters;

import com.motorola.dp.jenkinsmonitor.service.util.xml.RemoteXmlParsingService;

@Service("jenkinsMonitoringService")
public class DefaultJenkinsMonitoringService implements JenkinsMonitoringService {

    @Value("#{applicationProperties['jenkins.url'] + 'api/xml'}")
    private String xmlUrl;

    @Value("#{new com.motorola.dp.jenkinsmonitor.model.util.HttpRequestParameters(" +
                "jenkinsMonitoringService.xmlUrl" +
            ")}")
    private HttpRequestParameters jenkinsRequestParams;

    @Value("#{remoteXmlParsingService}")
    private RemoteXmlParsingService remoteXmlParsingService;

    @Scheduled(cron = "${jenkinsMonitor.cron}")
    public void checkJenkinsState() {
        //TODO: finish this method
        JenkinsState state = remoteXmlParsingService.parseRemoteXml(jenkinsRequestParams, JenkinsState.class);
    }

    public void setJenkinsRequestParams(HttpRequestParameters jenkinsRequestParams) {
        this.jenkinsRequestParams = jenkinsRequestParams;
    }

    public void setRemoteXmlParsingService(RemoteXmlParsingService remoteXmlParsingService) {
        this.remoteXmlParsingService = remoteXmlParsingService;
    }

    public void setXmlUrl(String xmlUrl) {
        this.xmlUrl = xmlUrl;
    }

    public String getXmlUrl() {
        return xmlUrl;
    }

}